import { View } from "../../../mvc/core/View";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../resource/ImagesConst";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { GTextFormat } from "../../../common/GTextFormat";
import { FontUtil } from "../../../common/font/FontUtil";
import { Cache } from "../../cache/Cache";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { EffectManager } from "../../manager/EffectManager";
import { UIIconEvent } from "../uiIconBtn/UIIconEvent";
type int = number;
//class GroupHintIcon
    
    export  class GroupHintIcon extends View
    {
        constructor(arg1: Boolean)
        {
            super();
            this._isCross = arg1;
            this.buttonMode = true;
            this.createChildren();
            return;
        }

        /* internal  */createChildren(): void
        {
            var loc1=GlobalClass.getBitmap(ImagesConst.GroupHintIcon);
            this.addChild(loc1);
            this._numLabel = new Object /* flash.text.TextField */();
            this._numLabel.selectable = false;
            this._numLabel.filters = [FilterConst.glowFilter];
            this._numLabel.width = loc1.width;
            this._numLabel.height = 10;
            this._numLabel.autoSize = flash.text.TextFieldAutoSize.RIGHT;
            this._numLabel.y = loc1.height - 14;
            addChild(this._numLabel);
            this.addEventListener(flash.events.MouseEvent.CLICK, this.onClick);
            return;
        }

        public set num(arg1: int)
        {
            this._num = arg1;
            this._numLabel.text = String(arg1);
            this._numLabel.setTextFormat(new GTextFormat(FontUtil.songtiName, 10, 16777215));
            return;
        }

        public get num(): int
        {
            return this._num;
        }

        public updateNum(): void
        {
            this.num = this.getReqNum();
            if (this.num == 0) 
            {
                this.removeFromUIIcon();
            }
            return;
        }

        /* internal  */getReqNum(): int
        {
            var loc2=null;
            var loc3=null;
            var loc1=0;
            if (this._isCross) 
            {
                loc2 = Cache.instance.crossGroup;
                if (loc2.inviteList && loc2.inviteList.length > 0) 
                {
                    loc1 = loc1 + loc2.inviteList.length;
                }
                if (loc2.applyList && loc2.applyList.length > 0) 
                {
                    loc1 = loc1 + loc2.applyList.length;
                }
            }
            else 
            {
                loc3 = Cache.instance.group;
                if (loc3.inviteList && loc3.inviteList.length > 0) 
                {
                    loc1 = loc1 + loc3.inviteList.length;
                }
                if (loc3.applyList && loc3.applyList.length > 0) 
                {
                    loc1 = loc1 + loc3.applyList.length;
                }
            }
            return loc1;
        }

        /* internal  */onClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this.num <= 0) 
            {
                this.removeFromUIIcon();
            }
            if (this._isCross) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.CrossGroup_OpenWin, null));
            }
            else 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.Group_OpenWin, null));
            }
            return;
        }

        public removeFromUIIcon(): void
        {
            if (this.parent) 
            {
                this.parent.removeChild(this);
                EffectManager.glowFilterUnReg(this);
                this.dispatchEvent(new UIIconEvent(UIIconEvent.RemoveIcon));
            }
            return;
        }

        /* internal */ /* var */_isCross: Boolean;

        /* internal */ /* var */_numLabel: Object /* flash.text.TextField */;

        /* internal */ /* var */_num: int=0;
    }
